package cn.tedu.crm.base.controller;

import cn.hutool.core.util.StrUtil;
import cn.tedu.crm.base.response.JsonResult;
import cn.tedu.crm.base.service.SmsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class SmsController {

    @Autowired
    private SmsService smsService;

    @GetMapping("/api/sms/send")
    public JsonResult send(String phone) {
        if (StrUtil.isEmpty(phone)) {
            return JsonResult.error("手机号不能为空");
        }
        if (!phone.matches("^1[3-9]\\d{9}$")) {
            return JsonResult.error("手机号格式错误");
        }
        smsService.send(phone);
        return JsonResult.success(null);
    }

}
